package com.xh.login.controller;

import cn.hutool.core.text.split.SplitIter;
import com.xh.login.entity.Result;
import com.xh.login.entity.TotalRow;
import com.xh.login.entity.User;
import com.xh.login.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 张园园
 */
@RestController
public class TableController {
    @Resource
    private UserService userService;
    @RequestMapping("data")
    public Object index(){
        System.out.println("正在查询数据");
        List<User> user = userService.index();
        TotalRow totalRow = new TotalRow("666","999");
        return new Result(200,totalRow,user,"请求成功",user.size());
    }
    @RequestMapping("add")
    public Object add(User user){
        int i = userService.addUser(user);
        TotalRow totalRow = new TotalRow("666","999");
        return new Result(200,totalRow,i,"请求成功",null);
    }
    @RequestMapping("delete/{id}")
    public Object delete(@PathVariable("id") Integer id){
        int i = userService.deleteUser(id);
        if (i > 0){
            return new Result(200,null,i,"请求成功",null);
        }
        System.out.println("小穆");
        return new Result(444,"请求失败");
    }
    @RequestMapping("update")
    public Object update(User user){
        int i = userService.updateUser(user);
        if (user==null){
            System.out.println("修改失败");
        }
        return new Result(200,null,user,"请求成功",null);
    }
}
